package com.innoking.docsys.workflow.controller;

import com.innoking.docsys.utils.JsonToOtherUtil;
import com.innoking.docsys.utils.OtherPojo;
import com.innoking.docsys.utils.ResultObjVO;
import com.innoking.docsys.workflow.module.WorkflowModelVO;
import com.innoking.docsys.workflow.service.WorkflowModelService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 描述:
 *
 * @author zyp
 * @description 工作流模型控制器
 * @create 2019-09-04 16:20
 */
@RestController
@RequestMapping("/workflowModel")
public class WorkflowModelController {

    Logger logger= LoggerFactory.getLogger(WorkflowModelController.class);

    @Autowired
    private WorkflowModelService workflowModelService;

    /**
     * @author:zyp
     * @description 获取工作流模型
     * @date: 2019/9/5 16:10
     * @return 
     */
    @PostMapping("/getActModel")
    public ResultObjVO getActModel(@RequestBody String data) {
        OtherPojo ob = JsonToOtherUtil.rtOtherPojo(data, new WorkflowModelVO());
        WorkflowModelVO workflowModel = (WorkflowModelVO)ob.getObj();
        ResultObjVO result = workflowModelService.getActModel(workflowModel);
        return result;
    }

    /**
     * @author:zyp
     * @description 创建工作流模型
     * @date: 2019/9/6 14:24
     * @param name:名称；key:工作流模型key；description:描述
     * @return
     */
    @PostMapping("/createModel")
    public ResultObjVO createModel(@RequestBody String data) {
        OtherPojo ob = JsonToOtherUtil.rtOtherPojo(data, new WorkflowModelVO() );
        WorkflowModelVO workflowModel = (WorkflowModelVO)ob.getObj();
        ResultObjVO result = workflowModelService.createModel(workflowModel);
        return result;
    }

    /**
     * @author:zyp
     * @description 删除模型
     * @date: 2019/9/6 15:05
     * @return
     */
    @PostMapping("/delModel")
    public ResultObjVO delModel(@RequestBody String data) {
        OtherPojo ob = JsonToOtherUtil.rtOtherPojo(data, new String() );
        String ids = (String)ob.getObj();
        ResultObjVO result = workflowModelService.delModel(ids);
        return result;
    }

    /**
     * @author:zyp
     * @description 部署模型、定义
     * @date: 2019/9/6 15:17
     * @return 
     */
    @PostMapping("/deployModel")
    public ResultObjVO deployModel(@RequestBody String data) {
        OtherPojo ob = JsonToOtherUtil.rtOtherPojo(data,new WorkflowModelVO() );
        WorkflowModelVO workflowModelVO = (WorkflowModelVO)ob.getObj();
        ResultObjVO result = workflowModelService.deployModel(workflowModelVO);
        return result;
    }

}